<?php
class Zgm_Controller_Plugin_Acl extends Zend_Controller_Plugin_Abstract
{
   const ROLE_PUBLIC_ID = 1;
   const ROLE_PRIVATE_ID = 2;
   
   private $_acl = null;
   private $_auth = null;
   
   public function __construct(Zend_Acl $acl, Zend_Auth $auth) {
     $this->_acl = $acl;
     $this->_auth = $auth;
   }
   
   public function preDispatch(Zend_Controller_Request_Abstract $request) {
      if($this->_auth->hasIdentity()) {
         $identity = $this->_auth->getIdentity();
         if ($identity['role_id'] == self::ROLE_PUBLIC_ID) {
            $role = 'public';
         } elseif ($identity['role_id'] == self::ROLE_PRIVATE_ID) {
            $role = 'private';
         }
      } else {
         $role = 'guest';
      }
//      $controller = $request->controller;
//      $action = $request->action;
//      if (!$this->_acl->isAllowed($role, $controller, $action)) {
//         if ($role == 'guest') {
//            $request->setControllerName('index');
//            $request->setActionName('index');
//         } else {
//            $request->setControllerName('error');
//            $request->setActionName('noauth');
//         }
//      }
   }
}